package com.zhiyou100.controller;

import com.zhiyou100.entity.Emp;
import com.zhiyou100.service.EmpService;
import com.zhiyou100.service.impl.EmpServiceImpl;
import netscape.javascript.JSException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;

@WebServlet("/myEmpServlet")
public class MyEmpServlet extends HttpServlet {
    EmpService empService= new EmpServiceImpl();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("MyEmpServlet1");
        request.setCharacterEncoding("UTF-8");
        // 接收参数
        String ename = request.getParameter("ename");
        String sal1 = request.getParameter("sal1");
        String sal2 = request.getParameter("sal2");
        String sex = request.getParameter("sex");
        String did = request.getParameter("did");
        System.out.println("MyEmpServlet2");
        System.out.println("开始接收数据");
        System.out.println(ename);
        System.out.println("----");

        HashMap<String,Object> map = new HashMap<>();
        System.out.println("mao="+map);
        map.put("ename",ename);
        map.put("sal1",sal1);
        map.put("sal2",sal2);
        map.put("sex",sex);
        map.put("did",did);

        List<Emp> empByMany = empService.getEmpByMany(map);

        System.out.println("+++++++++++++++++++++++++++");
        System.out.println(empByMany);
        //存域
        request.setAttribute("allEmp",empByMany);
        //跳转
        request.getRequestDispatcher("index.jsp").forward(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
